package com.ruoyi.web.controller.website;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.module.domain.WebArticle;
import com.ruoyi.module.service.IWebArticleService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 网页文章Controller
 *
 * @author fubojin
 * @date 2024-12-09
 */

@RestController
@RequestMapping("/website/article")
public class WebArticleController extends BaseController
{
    @Autowired
    private IWebArticleService webArticleService;

    /**
     * 查询网页文章列表
     */
//    @Anonymous
//    @PreAuthorize("@ss.hasPermi('system:article:list')")
    @GetMapping("/list")
    public TableDataInfo list(WebArticle webArticle)
    {
        startPage();
        List<WebArticle> list = webArticleService.selectWebArticleList(webArticle);
        return getDataTable(list);
    }

    /**
     * 导出网页文章列表
     */
//    @PreAuthorize("@ss.hasPermi('system:article:export')")
    @Log(title = "网页文章", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WebArticle webArticle)
    {
        List<WebArticle> list = webArticleService.selectWebArticleList(webArticle);
        ExcelUtil<WebArticle> util = new ExcelUtil<WebArticle>(WebArticle.class);
        util.exportExcel(response, list, "网页文章数据");
    }

    /**
     * 获取网页文章详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:article:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(webArticleService.selectWebArticleById(id));
    }
    /**
     * 获取网页文章详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:article:query')")
    @GetMapping(value = "/selectWebById/{id}")
    public AjaxResult getWebInfo(@PathVariable("id") Long id)
    {
        return success(webArticleService.selectWebById(id));
    }

    /**
     * 新增网页文章
     */
    @Log(title = "网页文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WebArticle webArticle)
    {
        return toAjax(webArticleService.insertWebArticle(webArticle));
    }

    /**
     * 修改网页文章
     */
    @Log(title = "网页文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WebArticle webArticle)
    {
        return toAjax(webArticleService.updateWebArticle(webArticle));
    }

    /**
     * 删除网页文章
     */
    @Log(title = "网页文章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(webArticleService.deleteWebArticleByIds(ids));
    }
}
